Your tween component must provide three functions in addition to the standard functions required to implement a component. The functions you must provide are TweenInitialize , TweenDoTween , and TweenReset . The following examples show a tween component that interpolates values for short integers. QuickTime provides a component for short integers ( kTweenTypeShort ) for you; you do not need to implement a component to handle interpolation of short integers yourself.
Listing 13-6 shows the TweenerShortInitialize function, which QuickTime calls to set up the component. In this example, TweenerShortInitialize simply returns. In a more complex example, TweenerShortInitialize might allocate storage to be used during the tween operation.
Listing 6 A function to initialize a tween component
pascal ComponentResult TweenerShortInitialize(TweenerComponent tc,
QTAtomContainer container,
QTAtom tweenAtom,
QTAtom dataAtom)
{
return noErr;
}
Listing 13-7 shows the TweenShortDoTween function, which QuickTime calls when it needs to send a tween value from the tween track to a media track. The data atom and the function that is called to set the value are stored in the tween record.
Listing 7 A function to set a value during a tween operation
pascal ComponentResult TweenShortDoTween(TweenerComponent tc,
TweenRecord *tr)
{
short *data;
short tFrom, tTo, tValue;
QTGetAtomDataPtr(tr->container, tr->dataAtom, nil, (Ptr *)&data);
tFrom = data[0];
tTo = data[1];
tValue = tFrom + FixMul(tTo - tFrom, tr->percent);
(tr->dataProc)((struct TweenRecord *)tr, &tValue,
sizeof(tValue), 1, nil, nil, nil, nil);
return noErr;
}
Listing 13-8 shows the TweenShortReset function, which QuickTime calls after the tween sample completes. In this example, because TweenerShortInitialize does not allocate any storage, TweenerShortReset simply returns. In a more complex example, TweenerShortReset would release any storage allocated by TweenerShortInitialize and any storage allocated during the tween operation.
Listing 8 A function to reset a tween component
pascal ComponentResult TweenerShortReset (TweenerComponent tc)
{
return noErr;
}